<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
    <h:head>
        <title>Registrazione</title>
          <ui:include src="Header.xhtml"/>
    </h:head>
    <h:body>
        <h:form>
    <p:panel id="panel" header="Form Registrazione" style="margin-bottom:10px;">
        <p:messages id="messages" autoUpdate="true" closable="true"/>
        <h:panelGrid id = "grid" columns="2" cellpadding="5">
            
            <p:outputLabel for="nome" value="Nome:" />
            <p:inputText id="nome" required="true" requiredMessage="Inserire nome" value="#{registrazione.nome}" />
 
            <p:outputLabel for="cognome" value="Cognome:" />
            <p:inputText id="cognome" required="true" requiredMessage="Inserire cognome" value="#{registrazione.cognome}" />
 
            <p:outputLabel for="via" value="Via:" />
            <p:inputText id="via" required="true" requiredMessage="Inserire via" value="#{registrazione.via}" />
            
                     
            <p:outputLabel for="provincia" value="Provincia"/> 
            <p:selectOneMenu id="provincia" required="true"  requiredMessage="Selezionare provincia" value="#{provinciaManaged.provincia}" converter ="provinciaConverter" >  
             <f:selectItem itemLabel="Seleziona Provincia" itemValue="" noSelectionOption="true"/>  
             <f:selectItems value="#{provinciaManaged.province}" var="p" itemLabel="#{p.nome}, #{p.sigla}" itemValue="#{p}" />             
             <p:ajax event="valueChange" update="comune" listener="#{provinciaManaged.handleComuni()}" />
            </p:selectOneMenu>  
            
            <p:outputLabel for="comune" value="Città"/> 
            <p:selectOneMenu id="comune" required="true" requiredMessage="Selezionare città" value="#{provinciaManaged.comune}" converter="comuneConverter" >  
             <f:selectItem itemLabel="Seleziona Città" itemValue="" noSelectionOption="true"/>  
             <f:selectItems value="#{provinciaManaged.comuni}" var="c" itemLabel="#{c.nome}" itemValue="#{c}"/>
            </p:selectOneMenu> 
            
            <p:outputLabel for="codpos" value="Codice Postale:" />
            <p:inputText id="codpos" required="true" requiredMessage="Inserire cap" value="#{registrazione.codicePostale}"/>
                      
            <p:outputLabel for="user" value="Username:" />
            <p:inputText id="user" required="true" requiredMessage="Inserire username" value="#{registrazione.username}" />
            
            <p:outputLabel for="password" value="Password:" />
            <p:password id="password" match="confermapassword" requiredMessage="Inserire password" promptLabel="Efficacia Password" 
            weakLabel="Fragile" goodLabel="Buona" strongLabel="Forte"
            validatorMessage="Le password inserite non corrispondono" required ="true" value="#{registrazione.password}" feedback="true"/>
            
            <p:outputLabel for="confermapassword" value="Conferma password:" />
            <p:password id="confermapassword" required="true" requiredMessage="Reinserire password" value="#{registrazione.password}"/>
            
            <p:outputLabel for="email" value="Email:" />
            <p:inputText id="email" required="true" requiredMessage="Inserire email" value="#{registrazione.email}"/>
            
                      
        </h:panelGrid>
    </p:panel>
    
            <p:commandButton value="Conferma Dati" action="#{registrazione.registra(provinciaManaged)}" update="grid"/>
    <p:commandButton type="reset" value="Reset"></p:commandButton> 
</h:form>
        <ui:include src="Footer.xhtml"/>  
    </h:body>
</html>

